package callingmechanism;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

public class MyClientHander extends SimpleChannelInboundHandler<Long> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Long aLong) throws Exception {
        System.out.println("服务器：" + channelHandlerContext.channel().remoteAddress() + "读取消息 " + aLong);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("MyClientHander 发送消息");
        ctx.writeAndFlush(1234567890123456789L);
        //ctx.writeAndFlush(Unpooled.copiedBuffer("abcdabcdabcdaabcd", CharsetUtil.UTF_8));//类型不对不会走编码器
    }
}
